<template>
  <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
      label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="客户姓名" prop="name">
            <el-input v-model="dataForm.name" placeholder="用户名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="手机号" prop="mobile">
            <el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="昵称" prop="nickName">
            <el-input v-model="dataForm.nickName" placeholder="昵称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="状态" prop="status">
            <el-select
              v-model="dataForm.status"
              placeholder="司机状态"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.sys_normal_disable"
                :key="Number(dict.value)"
                :label="dict.label"
                :value="Number(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="生日" prop="birthday">
            <el-date-picker
              style="width: 100%;"
              v-model="dataForm.birthday"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="性别" prop="sex">
            <el-select style="width: 100%;" v-model="dataForm.sex" placeholder="性别" clearable>
              <el-option
                v-for="dict in dict.type.sys_user_sex"
                :key="Number(dict.value)"
                :label="dict.label"
                :value="Number(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地址" prop="locationId">
            <el-input v-model="dataForm.locationId" placeholder="地址"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {
    addOrUpdate
  } from "@/api/business/client";
  export default {
    dicts: ['sys_user_sex','sys_normal_disable'],
    data() {
      return {
        title: '',
        visible: false,
        dataForm: {},
        dataRule: {
          name: [{
            required: true,
            message: '用户名不能为空',
            trigger: 'blur'
          }],
          mobile: [{
            required: true,
            message: '手机号不能为空',
            trigger: 'blur'
          }],
          createTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }],
        }
      }
    },
    methods: {
      init(record) {
        this.visible = true
        this.dataForm = record
        if (this.dataForm && this.dataForm.id) {
          this.title = '客户信息表' + '修改'
        } else {
          this.title = '客户信息表' + "新增"
        }
      },

      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            addOrUpdate(this.dataForm).then(res => {
              this.visible = false
              this.$modal.msgSuccess(this.title + "成功");
              this.$emit('refreshDataList')
            })
          }
        })
      }
    }
  }
</script>
